home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWShLiSh.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  9.7 KB  |  295 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWShLiSh.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWSHLISH_H
  13. #include "FWShLiSh.h"
  14. #endif
  15.  
  16. // ----- Foundation Includes -----
  17.  
  18. #ifndef FWSTREAM_H
  19. #include "FWStream.h"
  20. #endif
  21.  
  22. //========================================================================================
  23. //    RunTime Info
  24. //========================================================================================
  25.  
  26. #if FW_LIB_EXPORT_PRAGMAS
  27. #pragma lib_export on
  28. #endif
  29.  
  30. #ifdef FW_BUILD_MAC
  31. #pragma segment FWGraphics_ShapeListShape
  32. #endif
  33.  
  34. FW_DEFINE_CLASS_M1(FW_CShapeListShape, FW_CShape)
  35. FW_REGISTER_ARCHIVABLE_CLASS(FW_LShapeListShape, FW_CShapeListShape, FW_CShapeListShape::Read, FW_CShape::Write)
  36.  
  37. //========================================================================================
  38. //    class FW_CShapeListShape
  39. //========================================================================================
  40.  
  41. //----------------------------------------------------------------------------------------
  42. // FW_CShapeListShape::FW_CShapeListShape
  43. //----------------------------------------------------------------------------------------
  44.  
  45. FW_CShapeListShape::FW_CShapeListShape(const FW_PShapeList& list) :
  46.     FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  47.     fShapeList(list)
  48. {
  49.     FW_END_CONSTRUCTOR
  50. }
  51.  
  52. //----------------------------------------------------------------------------------------
  53. // FW_CShapeListShape::FW_CShapeListShape
  54. //----------------------------------------------------------------------------------------
  55.  
  56. FW_CShapeListShape::FW_CShapeListShape(FW_CReadableStream& archive) :
  57.     FW_CShape(archive),
  58.     fShapeList(archive)
  59. {
  60.     FW_END_CONSTRUCTOR
  61. }
  62.  
  63. //----------------------------------------------------------------------------------------
  64. // FW_CShapeListShape::FW_CShapeListShape
  65. //----------------------------------------------------------------------------------------
  66.  
  67. FW_CShapeListShape::FW_CShapeListShape(const FW_CShapeListShape& other) :
  68.     FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  69.     fShapeList(other.fShapeList)
  70. {
  71.     FW_END_CONSTRUCTOR
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. // FW_CShapeListShape::~FW_CShapeListShape
  76. //----------------------------------------------------------------------------------------
  77.  
  78. FW_CShapeListShape::~FW_CShapeListShape()
  79. {
  80.     FW_START_DESTRUCTOR
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // FW_CShapeListShape::HitTestList
  85. //----------------------------------------------------------------------------------------
  86.  
  87. FW_CShape* FW_CShapeListShape::HitTestList(FW_CGraphicContext& gc,
  88.                                            const FW_CPoint& test,
  89.                                            FW_CFixed tolerance) const
  90. {
  91.     FW_CShape* shape = NULL;
  92.     FW_CShapeListIterator ite(FW_CShapeListIterator::kFrontToBack, fShapeList);
  93.     while((shape = ite.Next()) != NULL)
  94.     {
  95.         if(shape->HitTest(gc, test, tolerance))
  96.             break;
  97.     }
  98.     
  99.     return shape;
  100. }
  101.  
  102. //----------------------------------------------------------------------------------------
  103. // FW_CShapeListShape::operator=
  104. //----------------------------------------------------------------------------------------
  105.  
  106. FW_CShapeListShape& FW_CShapeListShape::operator=(const FW_CShapeListShape& other)
  107. {
  108.     fShapeList = other.fShapeList;
  109.     return *this;
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. // FW_CShapeListShape::GetShapeList
  114. //----------------------------------------------------------------------------------------
  115.  
  116. FW_PShapeList FW_CShapeListShape::GetShapeList() const
  117. {
  118.     return fShapeList;
  119. }
  120.  
  121. //----------------------------------------------------------------------------------------
  122. // FW_CShapeListShape::SetShapeList
  123. //----------------------------------------------------------------------------------------
  124.  
  125. void FW_CShapeListShape::SetShapeList(const FW_PShapeList& list)
  126. {
  127.     fShapeList = list;
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. // FW_CShapeListShape::Purge
  132. //----------------------------------------------------------------------------------------
  133.  
  134. void FW_CShapeListShape::Purge()
  135. {
  136.     FW_CShape* shape;
  137.     FW_CShapeListIterator ite(FW_CShapeListIterator::kFrontToBack, fShapeList);
  138.     while((shape = ite.Next()) != NULL)
  139.         shape->Purge();
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. // FW_CShapeListShape::Render
  144. //----------------------------------------------------------------------------------------
  145.  
  146. void FW_CShapeListShape::Render(FW_CGraphicContext& gc) const
  147. {
  148.     FW_CShape* shape;
  149.     FW_CShapeListIterator ite(FW_CShapeListIterator::kBackToFront, fShapeList);
  150.     while((shape = ite.Next()) != NULL)
  151.         shape->Render(gc);
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // FW_CShapeListShape::Render
  156. //----------------------------------------------------------------------------------------
  157.  
  158. void FW_CShapeListShape::RenderShapeList(FW_CGraphicContext& gc,
  159.                                          const FW_PShapeList& shapeList)
  160. {
  161.     FW_CShape* shape;
  162.     FW_CShapeListIterator ite(FW_CShapeListIterator::kBackToFront, shapeList);
  163.     while((shape = ite.Next()) != NULL)
  164.         shape->Render(gc);
  165. }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. // FW_CShapeListShape::Copy
  169. //----------------------------------------------------------------------------------------
  170.  
  171. FW_CShape* FW_CShapeListShape::Copy() const
  172. {
  173.     return FW_NEW(FW_CShapeListShape, (*this));
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. // FW_CShapeListShape::HitTest
  178. //----------------------------------------------------------------------------------------
  179.  
  180. FW_Boolean FW_CShapeListShape::HitTest(FW_CGraphicContext& gc,
  181.                                         const FW_CPoint& test,
  182.                                         FW_CFixed tolerance) const
  183. {
  184.     if (GetRenderVerb() == FW_kNoRendering)
  185.         return NULL;
  186.  
  187.     return HitTestList(gc, test, tolerance) != NULL;
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. // FW_CShapeListShape::Transform
  192. //----------------------------------------------------------------------------------------
  193.  
  194. void FW_CShapeListShape::Transform(Environment *ev, ODTransform* transform)
  195. {
  196.     FW_CShape* shape;
  197.     FW_CShapeListIterator ite(FW_CShapeListIterator::kFrontToBack, fShapeList);
  198.     while((shape = ite.Next()) != NULL)
  199.         shape->Transform(ev, transform);
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. // FW_CShapeListShape::InverseTransform
  204. //----------------------------------------------------------------------------------------
  205.  
  206. void FW_CShapeListShape::InverseTransform(Environment *ev, ODTransform* transform)
  207. {
  208.     FW_CShape* shape;
  209.     FW_CShapeListIterator ite(FW_CShapeListIterator::kFrontToBack, fShapeList);
  210.     while((shape = ite.Next()) != NULL)
  211.         shape->InverseTransform(ev, transform);
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // FW_CShapeListShape::MoveShape
  216. //----------------------------------------------------------------------------------------
  217.  
  218. void FW_CShapeListShape::MoveShape(FW_CFixed deltaX, FW_CFixed deltaY)
  219. {
  220.     FW_CShape* shape;
  221.     FW_CShapeListIterator ite(FW_CShapeListIterator::kFrontToBack, fShapeList);
  222.     while((shape = ite.Next()) != NULL)
  223.         shape->MoveShape(deltaX, deltaY);
  224. }
  225.  
  226. //----------------------------------------------------------------------------------------
  227. // FW_CShapeListShape::MoveShapeTo
  228. //----------------------------------------------------------------------------------------
  229.  
  230. void FW_CShapeListShape::MoveShapeTo(FW_CFixed x, FW_CFixed y)
  231. {
  232.     FW_CShape* shape;
  233.     FW_CShapeListIterator ite(FW_CShapeListIterator::kFrontToBack, fShapeList);
  234.     while((shape = ite.Next()) != NULL)
  235.         shape->MoveShapeTo(x, y);
  236. }
  237.     
  238. //----------------------------------------------------------------------------------------
  239. // FW_CShapeListShape::Inset
  240. //----------------------------------------------------------------------------------------
  241.  
  242. void FW_CShapeListShape::Inset(FW_CFixed h, FW_CFixed v)
  243. {
  244.     FW_CShape* shape;
  245.     FW_CShapeListIterator ite(FW_CShapeListIterator::kFrontToBack, fShapeList);
  246.     while((shape = ite.Next()) != NULL)
  247.         shape->Inset(h, v);
  248. }
  249.     
  250. //----------------------------------------------------------------------------------------
  251. // FW_CShapeListShape::GetBounds
  252. //----------------------------------------------------------------------------------------
  253.  
  254. void FW_CShapeListShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
  255. {
  256.     FW_CShapeListIterator ite(FW_CShapeListIterator::kFrontToBack, fShapeList);
  257.     FW_CShape* shape = ite.First();
  258.     
  259.     if(shape == NULL)
  260.     {
  261.         rect.SetInt(0, 0, 0, 0);
  262.     }
  263.     else
  264.     {
  265.         shape->GetBounds(gc, rect);
  266.  
  267.         while((shape = ite.Next()) != NULL)
  268.         {
  269.             FW_CRect bounds;
  270.             shape->GetBounds(gc, bounds);
  271.             rect.Union(bounds);
  272.         }
  273.     }
  274. }
  275.  
  276. //----------------------------------------------------------------------------------------
  277. // FW_CShapeListShape::Flatten
  278. //----------------------------------------------------------------------------------------
  279.  
  280. void FW_CShapeListShape::Flatten(FW_CWritableStream& archive) const
  281. {
  282.     FW_CShape::Flatten(archive);
  283.     fShapeList->Flatten(archive);
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. // FW_CShapeListShape::Read
  288. //----------------------------------------------------------------------------------------
  289.  
  290. void* FW_CShapeListShape::Read(FW_CReadableStream& archive)
  291. {
  292.     FW_CShapeListShape* rep = FW_NEW(FW_CShapeListShape, (archive));
  293.     return rep;
  294. }
  295.